Skip to content

Conversation

@buffalojoec
Copy link
Contributor

@buffalojoec buffalojoec commented Jun 11, 2024

Benchmarking compute unit usage for the BPF implementation of the
Config program using Mollusk.

Mollusk's CU bencher is designed to profile compute unit usage for a series
of benchmark instructions.

The bencher will only write a new table to the markdown file if CU usage has
changed. With this in mind, we can integrate CU benching into our CI so that
if there is ever a change to the program that affects CUs, the file must be
committed with the new benchmarks.

@buffalojoec buffalojoec marked this pull request as ready for review October 22, 2024 15:40
@buffalojoec buffalojoec force-pushed the bench-compute branch 2 times, most recently from 9de22ab to 94cd34c Compare October 22, 2024 15:55
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really great overall! Just some small things

bench_program_compute_units:
name: Benchmark Program Compute Units
runs-on: ubuntu-latest
needs: build_programs # Cargo Bench won't build the SBPF binary...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need cargo bench-sbf 😅

Comment on lines +15 to +16
'--features',
'bpf-entrypoint',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 thank you for doing this

Comment on lines +115 to +117
fn max_space() -> u64 {
bincode::serialized_size(&Self::default()).unwrap()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, but this function is the same for all implementations, so you may as well define it in the trait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this is from the ConfigState trait, which is required for the instruction helper store. I could just not use the helper, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha, this can stay as is, no worries!

Comment on lines +25 to +28
/// Convert to a `Bench`.
pub fn bench(&self) -> Bench {
(self.label.as_str(), &self.instruction, &self.accounts)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for mollusk-svm-bencher: but it would be clearer to have Bench be a struct

@febo
Copy link

febo commented Oct 23, 2024

if there is ever a change to the program that affects CUs, the file must be
committed with the new benchmarks

This is great!

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two last tiny things, everything else looks great!

+ key_len * entry_size
let total_keys_size = (key_len).checked_mul(entry_size).unwrap();
bincode::serialized_size(&(ConfigKeys::default(), MyConfig::default()))
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is the ok() needed? I thought you could just do and_then on the Result: https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only did it because checked_add returns an option, so it was one less unwrap(). I suppose it's all the same, though.

@@ -1,4 +1,4 @@
#![cfg(feature = "test-sbf")]
// #![cfg(feature = "test-sbf")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out?

@buffalojoec buffalojoec merged commit fa8b70a into main Oct 23, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants